package jp.co.piratealliance.pirateAllianceWeb.web.action.task;

import java.util.List;

import jp.co.piratealliance.pirateAllianceWeb.common.base.BaseAction;
import jp.co.piratealliance.pirateAllianceWeb.dto.com.UserInfoDto;
import jp.co.piratealliance.pirateAllianceWeb.dto.order.OrderInfoDto;
import jp.co.piratealliance.pirateAllianceWeb.dto.task.ScheduleAndEventInfoDto;
import jp.co.piratealliance.pirateAllianceWeb.dto.task.TaskFeeDetailInfoDto;
import jp.co.piratealliance.pirateAllianceWeb.dto.task.TaskInfoDto;
import jp.co.piratealliance.pirateAllianceWeb.service.task.TaskService;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;


/**
 * copyright pirate alliance team 2014
 *
 * @author lw
 */

public class TaskManagerWebAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private TaskService taskService;

	private List<TaskInfoDto> taskList;
	
	private TaskInfoDto taskInfo;
	
	private List<TaskFeeDetailInfoDto> feeDetailList;
	
	private List<ScheduleAndEventInfoDto> eventList;
	//费用总额
	private String amountStr;
	
	//说明
	private String description;
	
	//任務登録页面初期化
	public String taskManagerInit()
	{
		//TODO USERID
		//String userId="testabc";
		UserInfoDto userDto=(UserInfoDto) ActionContext.getContext().getSession().get("user");
		if(userDto!=null){
			this.taskList = this.taskService.getTaskListByUserId(userDto.getUser_id());
			return SUCCESS;
		}
		return INPUT;
	}
	
	//指定任務选定后该任务详细情况初期化
	public String setTaskInfoInit()
	{
		this.taskManagerInit();
		String orderId = ServletActionContext.getRequest().getParameter("orderId");
		
		this.taskInfo =  this.taskService.getTaskInfoByOrderId(orderId);
		this.feeDetailList = this.taskService.getFeeDetailListByOrderId(orderId);
		this.eventList = taskService.getEventListByUserId(orderId);
		//总额计算
		float amount = 0.0f;
		for(TaskFeeDetailInfoDto feeDto : feeDetailList){
			float price = feeDto.getPrice();
			amount += price;
		}
		this.amountStr = String.valueOf(amount);
		
		return SUCCESS;
	}
	
	//任務登録页面初期化
	public String saveTaskInfo()
	{
		OrderInfoDto orderInfoDto = new OrderInfoDto();
		orderInfoDto.setOrder_id(taskInfo.getOrder_id());
		orderInfoDto.setDescriptionx(description);
		orderInfoDto.setOperate_type(0);
		this.taskService.saveTaskInfo(orderInfoDto);
		return SUCCESS;
	}
	

	public TaskService getTaskService() {
		return taskService;
	}

	public void setTaskService(TaskService taskService) {
		this.taskService = taskService;
	}

	public List<TaskInfoDto> getTaskList() {
		return taskList;
	}

	public void setTaskList(List<TaskInfoDto> taskList) {
		this.taskList = taskList;
	}

	public List<TaskFeeDetailInfoDto> getFeeDetailList() {
		return feeDetailList;
	}

	public void setFeeDetailList(List<TaskFeeDetailInfoDto> feeDetailList) {
		this.feeDetailList = feeDetailList;
	}

	public TaskInfoDto getTaskInfo() {
		return taskInfo;
	}

	public void setTaskInfo(TaskInfoDto taskInfo) {
		this.taskInfo = taskInfo;
	}

	public String getAmountStr() {
		return amountStr;
	}

	public void setAmountStr(String amountStr) {
		this.amountStr = amountStr;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<ScheduleAndEventInfoDto> getEventList() {
		return eventList;
	}

	public void setEventList(List<ScheduleAndEventInfoDto> eventList) {
		this.eventList = eventList;
	}
	
	
}